<template>
  <el-dialog
    title="新建门店"
    :close-on-click-modal="false"
    :visible.sync="visible"
	:center="true"
	width="50%">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="餐馆名字" prop="name">
      <el-input v-model="dataForm.name" placeholder="餐馆名字"></el-input>
    </el-form-item>
    <el-form-item label="地址" prop="address">
      <el-input v-model="dataForm.address" placeholder="地址"></el-input>
    </el-form-item>
    <el-form-item label="联系人" prop="linkName">
      <el-input v-model="dataForm.linkName" placeholder="联系人"></el-input>
    </el-form-item>
    <el-form-item label="联系电话" prop="linkTel">
      <el-input v-model="dataForm.linkTel" placeholder="联系电话"></el-input>
    </el-form-item>
    <el-form-item label="餐馆电话" prop="sellerTel">
      <el-input v-model="dataForm.sellerTel" placeholder="餐馆电话"></el-input>
    </el-form-item>
    <el-form-item label="服务商编号" prop="serviceProviderNo">
      <el-input v-model="dataForm.serviceProviderNo" placeholder="服务商编号"></el-input>
    </el-form-item>
	<el-form-item label="餐馆介绍" prop="introduction">
	  <el-input type="textarea" v-model="dataForm.introduction" placeholder="餐馆介绍"></el-input>
	</el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" :disabled="disabledSubmit">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          sellerId: '',
          userId: '',
          name: '',
          address: '',
          linkName: '',
          linkTel: '',
          sellerTel: '',
          registerTime: '',
          openTime: '',
          policy: '',
          introduction: '',
          prompt: '',
          ewmLogo: '',
          idCardImg1: '',
          idCardImg2: '',
          serviceProviderNo: '',
          businessLicense: '',
          other: '',
          status: '',
          sqTime: '',
          bdId: '',
          yeOpen: '',
          wxOpen: '',
          ddOpen: '',
          lnt: '',
          lat: '',
          reserveRemind: '',
          tags: '',
          businessType: '',
          cuisineStyle: '',
          remark: ''
        },
        dataRule: {
          name: [
            { required: true, message: '名字不能为空', trigger: 'blur' }
          ],
          address: [
            { required: true, message: '地址不能为空', trigger: 'blur' }
          ],
          linkName: [
            { required: true, message: '联系人不能为空', trigger: 'blur' }
          ],
          linkTel: [
            { required: true, message: '联系电话不能为空', trigger: 'blur' }
          ],
          sellerTel: [
            { required: true, message: '餐馆电话不能为空', trigger: 'blur' }
          ],
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/store/tstoreseller/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.name = data.tStoreSeller.name
                this.dataForm.address = data.tStoreSeller.address
                this.dataForm.linkName = data.tStoreSeller.linkName
                this.dataForm.linkTel = data.tStoreSeller.linkTel
                this.dataForm.sellerTel = data.tStoreSeller.sellerTel
                this.dataForm.introduction = data.tStoreSeller.introduction
                this.dataForm.businessType = data.tStoreSeller.businessType
                this.dataForm.cuisineStyle = data.tStoreSeller.cuisineStyle
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/store/tstoreseller/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'sellerId': Number(new this.$snowFlakeId().generate()),
                'name': this.dataForm.name,
                'address': this.dataForm.address,
                'linkName': this.dataForm.linkName,
                'linkTel': this.dataForm.linkTel,
                'sellerTel': this.dataForm.sellerTel,
                'introduction': this.dataForm.introduction,
                'serviceProviderNo': this.dataForm.serviceProviderNo,
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
